<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Shop;

/**
 * ShopSearch represents the model behind the search form about `common\models\Shop`.
 */
class ShopSearch extends Shop
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['s_id'], 'integer'],
            [['s_name', 's_pass', 'dianname', 's_dizi', 'type', 's_logo', 'back_img'], 'safe'],
            [['shenhe', 'phone'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Shop::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            's_id' => $this->s_id,
            'shenhe' => $this->shenhe,
            'phone' => $this->phone,
        ]);

        $query->andFilterWhere(['like', 's_name', $this->s_name])
            ->andFilterWhere(['like', 's_pass', $this->s_pass])
            ->andFilterWhere(['like', 'dianname', $this->dianname])
            ->andFilterWhere(['like', 's_dizi', $this->s_dizi])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 's_logo', $this->s_logo])
            ->andFilterWhere(['like', 'back_img', $this->back_img]);

        return $dataProvider;
    }
}
